package com.cskaoyan.app.controller;

import com.cskaoyan.app.bean.common.BasePageInfo;
import com.cskaoyan.app.bean.common.BaseRespVo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.*;
import com.cskaoyan.app.exception.ValidationException;
import com.cskaoyan.app.service.AdminUserService;
import com.cskaoyan.app.util.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    @GetMapping("admin/user/list")
    public BaseRespVo<CommonData<MarketUser>> listUsers(@Validated BasePageInfo pageParam, BindingResult bindingResult,
            String username, String mobile)
            throws ValidationException {
        ValidationUtil.valid(bindingResult);
        CommonData<MarketUser> data = adminUserService.listUsers(pageParam, username, mobile);
        return BaseRespVo.ok(data);
    }

    @GetMapping("admin/user/detail")
    public BaseRespVo<MarketUser> getUserDetail(Integer id) throws ValidationException {
        if (id == null) {
            throw new ValidationException("id校验失败！");
        }
        MarketUser user = adminUserService.getUserDetailById(id);
        return BaseRespVo.ok(user);
    }

    @GetMapping("admin/address/list")
    public BaseRespVo<CommonData<MarketAddress>> listAddr(@Validated BasePageInfo pageParam,
          BindingResult bindingResult, String name, Integer userId) throws ValidationException {
        ValidationUtil.valid(bindingResult);
        CommonData<MarketAddress> data = adminUserService.listAddr(pageParam, name, userId);
        return BaseRespVo.ok(data);
    }

    @GetMapping("admin/collect/list")
    public BaseRespVo<CommonData<MarketCollect>> listCollect (@Validated BasePageInfo pageParam,
          BindingResult bindingResult, Integer userId, Integer valueId) throws ValidationException {
        ValidationUtil.valid(bindingResult);
        CommonData<MarketCollect> data = adminUserService.listCollect(pageParam, userId, valueId);
        return BaseRespVo.ok(data);
    }

    @GetMapping("admin/footprint/list")
    public BaseRespVo<CommonData<MarketFootprint>> listFootPrint(@Validated BasePageInfo pageParam,
         BindingResult bindingResult, Integer userId, Integer goodsId) throws ValidationException {
        ValidationUtil.valid(bindingResult);
        CommonData<MarketFootprint> data = adminUserService.listFootPrint(pageParam, userId, goodsId);
        return BaseRespVo.ok(data);
    }

    @GetMapping("admin/history/list")
    public BaseRespVo<CommonData<MarketSearchHistory>> listHistory(@Validated BasePageInfo pageParam,
           BindingResult bindingResult, Integer userId, String keyword) throws ValidationException {
        ValidationUtil.valid(bindingResult);
        CommonData<MarketSearchHistory> data = adminUserService.listHistory(pageParam, userId, keyword);
        return BaseRespVo.ok(data);
    }

    @GetMapping("admin/feedback/list")
    public BaseRespVo<CommonData<MarketFeedback>> listFeedback(@Validated BasePageInfo pageParam,
           BindingResult bindingResult, Integer id, String username) throws ValidationException {
        ValidationUtil.valid(bindingResult);
        CommonData<MarketFeedback> data = adminUserService.listFeedback(pageParam, id, username);
        return BaseRespVo.ok(data);
    }
}
